package com.solarStruggle.domain

import stats._

trait ShardFactory {
	def apply(): Shard

	def singleton: Shard
}

object ShardRegistry {

	/**
	 * Global registry of all chassis types
	 */
	var chassis: List[ShardFactory] = List(
		Shuttle1, Shuttle2, Shuttle3,
		Cruiser1, Cruiser2, Cruiser3,
		Sphere1, Sphere2, Sphere3,
		Garden1, Garden2, Garden3,
		Satellite1, Satellite2, Satellite3)

	/**
	 * Global registry of all material types
	 */
	var materials: List[ShardFactory] = List(
		Plastics1, Plastics2, Plastics3,
		Titanium1, Titanium2, Titanium3,
		Steel1, Steel2, Steel3)

	/**
	 * Global registry of all engine types
	 */
	var engines: List[ShardFactory] = List(
		Thrusters1, Thrusters2, Thrusters3,
		Solar1, Solar2, Solar3,
		LiquidFuel1, LiquidFuel2, LiquidFuel3,
		WarpDrive
	)

	/**
	 * Global registry of all shield types
	 */
	var shields: List[ShardFactory] = List(
		EnergyShield1, EnergyShield2, EnergyShield3,
		PhysicalShield1, PhysicalShield2, PhysicalShield3,
		StealthShield1, StealthShield2, StealthShield3)

	/**
	 * Global registry of all weapon types
	 */
	var weapons: List[ShardFactory] = List(
		Lasers1, Lasers2, Lasers3,
		Torpedoes1, Torpedoes2, Torpedoes3,
		Nukes1, Nukes2, Nukes3)

	/**
	 * Global registry of all pod types
	 */
	var pods: List[ShardFactory] = List(
		Hibernation,
		LivingQuarters,
		Hydroponics,
		Lander,
		CargoHold,
		RepairStation,
		MassDisplacement)
}

/**
 * A Shard is a part which can be combined to make a Vehicle.
 */
abstract class Shard {

	/**
	 * The name of the shard, as displayed to the user
	 * 
	 * TODO: Internationalize
	 */
	def name: String

	/**
	 * The description of the shard displayed to the user.
	  * 
	 * TODO: Internationalize
	 */
	def description: String

	/**
	 * How much this shard costs.
	 */
	def cost: Int

	/**
	 * How many research points must be spent to obtain this shard.
	 */
	def researchCost: Int

	/**
	 * How much this shard adds to the weight of the vehicle
	 */
	def mass: Int

	/**
	 * How much energy this shard consumes
	 */
	def energy: Int

	/**
	 * Name of the SVG file used to represent this shard graphically
	 */
	def svgFile: String = "Generic.svg"

	override def toString(): String = name

}

/**
 * A chassis is the frame surrounding a vehicle.  It will usually have a negative energy value,
 * indicating that it provides energy to the rest of the vehicle.  It usually makes up the bulk
 * of the mass and cost of a vehicle, and determines how many engine, weapon, and pod shards the
 * vehicle can support.
 */
abstract class Chassis 
extends Shard {

	/**
	 * The maximum number of engines which can be attached to vehicles with this chassis
	 */
	def maxEngines: Int

	/**
	 * The maximum number of weapons which can be attached to vehicles with this chassis
	 */
	def maxWeapons: Int

	/**
	 * The maximum number of pods which can be attached to vehicles with this chassis
	 */
	def maxPods: Int

}

/**
 * The material from which the vehicle is constructed.  This sets the defense level once shields
 * (if any) are down
 */
abstract class Material
extends Shard {

	/**
	 * How much defense the material provides.  This only comes into play if there are no shields
	 * protecting the vehicle.  This protects against both energy and physical attacks.
	 */
	def defense: Int

}

/**
 * The engine provides a thrust force to move the vehicle.  The combined force of its engines 
 * weighed against the vehicle's mass determines how far the vehicle can move in a turn.
 */
abstract class Engine
extends Shard {

	/**
	 * The force of thrust provided by the engine
	 */
	def force: Int

}

/**
 * The shield is the first line of defense against physical attacks.  Shields have their own
 * set of health, separate from that of the vehicle itself.  This resets with each value.  Shields
 * can protect against energy attacks, physical attacks, or both to varying degrees.
 */
abstract class Shield
extends Shard {

	/**
	 * Amount of protection provided against energy attacks
	 */
	def energyDef: Int

	/**
	 * Amount of protection provided against physical attacks
	 */
	def physicalDef: Int

}

/**
 * Weapons are used to attack other vehicles.  They can be used against any vehicle within a given
 * area circling the ship, defined by its insideRadius and outsideRadius.  Some weapons may create
 * an explosion, affecting all vehicles in the area.  Weapons can deal physical damage, energy
 * damage, or both to varying degrees
 */
abstract class Weapon
extends Shard {

	/**
	 * The radius from the ship where the weapon cannot reach because the enemy is too close
	 */
	def insideRadius: Int

	/**
	 * The radius from the ship outside of which the weapon cannot reach because the enemy is too
	 * far away
	 */
	def outsideRadius: Int

	/**
	 * Amount of physical damage dealt
	 */
	def physicalDamage: Int

	/**
	 * Amount of energy damage dealt
	 */
	def energyDamage: Int

	/**
	 * Radius of the explosion
	 */
	def blastRadius: Int

}

/**
 * Pods are modules which endow special capabilities, such as the ability to transport civilians,
 * depending on the pod.
 */
abstract class Pod
extends Shard {
}
